home *** CD-ROM | disk | FTP | other *** search
/ Internet Toolkit / Internet Toolkit.iso / info / lumberja / lumberjak < prev   
Text File  |  1993-04-05  |  6KB  |  203 lines

  1. #!/usr/bin/perl -- # -*-Perl-*-
  2.  
  3. # local defines
  4. $OPERPASSFILE = '/other/irc/lib/robot.pw';
  5.  
  6. # variables:
  7. #    $port, $server    - server to connect to
  8. #    $servername       - name of the server we're on
  9. #                        (what the server calls itself)
  10. #    $nick             - nickname
  11. #    $fullname         - full name field
  12. #    $username         - username to use with server
  13. #    S                 - socket file handle
  14. #    $source           - source of a remote message
  15. #    $quitflag         - set to 1 to quit
  16. #    $lord             - my lord and liege
  17. #    $magicword        - how do you make me leave?
  18. #    $eavesdrop        - forward MSGs to lord
  19. #    $biff             - REALLY COOL MODE DOOD
  20. #    $verbose          - debugging mode
  21. #    $talk             - like stuff a lot
  22. #    $greet            - say hi to people
  23. #    %lastpriv         - last msg from whoever
  24.  
  25. # primitive support functions
  26.  
  27. sub Upcase {            # upcase the arg & return it
  28.     local($string) =@_;
  29.     $string =~ tr/a-z/A-Z/;
  30.     $string;
  31. }
  32.  
  33. sub StripLeadingColon {        # strips the leading colon if any from $arg
  34.     local($string) = @_;    # and returns the str without the :
  35.     $string =~ s/^://;        # (written because IRC has so many :msgs)
  36.     $string;
  37. }
  38. # cmdline parsing now uses getopt.pl for ease of expansion
  39. $| = 1;                # allow for debug messages
  40.  
  41. push(@INC,'/home/ckd/lib/perl');
  42.  
  43. require 'getopts.pl';
  44. require 'ircclient.pl';
  45. require 'ctime.pl';
  46.  
  47. do Getopts('p:s:n:f:u:l:c:d:o');
  48. # port, server, nick, fullname, username, lord, channel, magicword, dumpfile
  49. # Booleans: o = oper, e = eavesdrop, v = verbose-debug, b = biff, t = talk,
  50. # g = greet, r= revenger
  51.  
  52. $port = $opt_p || $ENV{'IRCPORT'} || 6667;
  53. $server = $opt_s || $ENV{'IRCSERVER'} || 'eff.org';
  54. $nick = $opt_n || $ENV{'IRCAUTONICK'} || 'LumberJak';
  55. $fullname = $opt_f || $ENV{'IRCAUTONAME'} || 'I log all night and I log all day';
  56. $username = $opt_u || getlogin || (getpwuid($<))[0];
  57. $lord = $opt_l || $ENV{'IRCNICK'} || $ENV{'USER'} || (getpwuid($<))[0] ||
  58.     die "The death of God left the angels in a strange position";
  59. $channel = $opt_c || "#Twilight_Zone";
  60. #$magicword = $opt_m || 'Bernstein';
  61. $delay = 1;
  62. $dumpfile =  $opt_d || '/home/hrose/trillian/ircstuff/bot.dumplog';
  63.  
  64. #$eavesdrop = $opt_e; $debug = $opt_v; $biff = $opt_b;
  65. #$talk = $opt_t; $greet = $opt_g; $vengeance = $opt_r;
  66.  
  67.  
  68. chop($operpass = `head -1 $OPERPASSFILE`);
  69.  
  70.  
  71. open(LOGFILE,">>$dumpfile");
  72. select ((select (LOGFILE),$|=1)[0]);
  73. &ircclient'bindsocket('S',$server,$port);
  74.  
  75. # now we have a socket connected to the server, time to play
  76.  
  77. # first, signon as a client
  78. &ircclient'nick($nick);
  79. &ircclient'user($username,$username,$server,$fullname);
  80. if ($operpass) {
  81.     &ircclient'oper('robotman',$operpass);
  82. }
  83.  
  84. &ircclient'join($channel);
  85.  
  86. # next, completely ignore the message of the day
  87. # while getting the server's name for itself
  88.  
  89.  munchmotd:
  90.     while (<S>) {
  91.     chop;
  92.     ($servername) = m/.*Your host is ([^ ,]+),.*/
  93.         if m/Your host is/;
  94.     if (( m!End of /MOTD command! ) ||
  95.         ( m!Message-of-today is missing! )) {
  96.         last munchmotd;
  97.     }
  98.     }
  99.  
  100. $servername = $server unless $servername; # do some simple trapping for oldies
  101.  
  102.  mainloop: while (<S>) {
  103.      chop;
  104.      $_ = ":$servername $_" unless /^:/;
  105.      ($source, $command, $parms) = split(/ /,$_,3);
  106.      $source = &StripLeadingColon($source);
  107.      $cmd = &Upcase($command);
  108.    cmdcase:            # treated as a switch/case type thingy
  109.      {            # as long as you're careful about eq
  110.      if ($cmd eq 'CHANNEL') {&ParseChan($source,$cmd,$parms);
  111.                  last cmdcase;};
  112.      if ($cmd eq 'JOIN') {&ParseChan($source,$cmd,$parms);
  113.                   last cmdcase;};
  114.      if ($cmd eq 'PART') {&ParseChan($source,$cmd,$parms);
  115.                   last cmdcase;};
  116.      if ($cmd eq 'INVITE') {&ParseInvite($source,$parms);
  117.                 last cmdcase;};
  118.      if ($cmd eq 'MSG') {&ParseMsg($source,$parms);
  119.                  last cmdcase;};
  120.      if ($cmd eq 'NOTICE') {&ParseNotice($source,$parms);
  121.                 last cmdcase;};
  122.      if ($cmd eq 'PING') {&ircclient'pong($nick);
  123.                   last cmdcase;};
  124.      if ($cmd eq 'PRIVMSG') {&ParsePriv($source,$parms);
  125.                  last cmdcase;};
  126.      if ($cmd eq 'WALLOPS') {&ParseWallops($source,$parms);
  127.                  last cmdcase;};
  128.      if ($cmd eq 'WALL') {&ParseWall($source,$parms);
  129.                   last cmdcase;};
  130.      if ($cmd eq 'QUIT') {&ParseQuit($source,$parms);
  131.                   last cmdcase;};
  132.      if ($cmd eq 'NAMREPLY') {&ParseNamReply($source,$parms);
  133.                   last cmdcase;};
  134.      }        
  135.      
  136.  } continue {
  137.      if ($quitflag)
  138.      {&Quit;}
  139. }
  140.  
  141. # nifty parse stuff
  142. sub ParseChan {
  143.     local ($who, $cmd, $chan)= @_;
  144. #    print LOGFILE "$who ${cmd}ed $chan\n";
  145.     print LOGFILE "$who ${cmd}ed $chan at ",&ctime(time);    
  146. }
  147. sub ParseInvite {
  148.     local ($who, $args) = @_;
  149.     print LOGFILE "$who invited me to $args\n";
  150.     &ircclient'notice($who,"Sorry, I'd rather stay here.");
  151. }
  152.  
  153. sub ParsePriv {
  154.     local($src,$args) = @_;
  155.     
  156.     local($target,$message) = split(/ /,$args,2);
  157.  
  158.     $target = "me" if $target =~ /$nick/i;
  159.     $message = &StripLeadingColon($message);
  160.     
  161.     print LOGFILE "$src told $target \"$message\".\n";
  162.     
  163. }
  164.  
  165. sub ParseNamReply {
  166.     local ($src,$args) = @_;
  167.     print LOGFILE "NAMREPLY = $args\n";
  168. }
  169.  
  170. sub ParseNotice {
  171.     local ($src,$args) = @_;
  172.     local($target,$message) = split(/ /,$args,2);
  173.  
  174.     $target = "me" if $target =~ /$nick/i;
  175.     $message = &StripLeadingColon($message);
  176.     
  177.     print LOGFILE "$src NOTICEd $target \"$message\".\n";
  178. }
  179. sub ParseChanMsg {
  180.     local($src,$target,$message) = @_;
  181.     print LOGFILE "$src told $target \"$message\".\n";
  182. }
  183.  
  184. sub ParseWallops {
  185.     local ($src,$args) = @_;
  186.     print LOGFILE "$src walloped $args at ",&ctime(time);
  187. }
  188.  
  189. sub ParseWall {
  190.     local ($src,$args) = @_;
  191.     print LOGFILE "$src WALLed $args\n";
  192. }
  193.  
  194. sub ParseQuit {
  195.     local ($src,$args) = @_;
  196.     print LOGFILE "$src QUIT at ",&ctime(time);
  197. }
  198.  
  199. sub Quit {
  200.     &ircclient'privmsg($lord,"Hey, man, I'm outa here.");
  201.     &ircclient'quit;
  202. }
  203.